import axios from "axios"
import type { RouteRecordNormalized } from "vue-router"
import userHttpRequest from "@/db/user"
import type * as User from "./type"
import { ResetPasswordData } from "./type"

// 登录
export function login(data: User.LoginData) {
  return userHttpRequest.login<User.LoginRes>(data)
}

// 获取用户信息
export function getUserInfo() {
  return userHttpRequest.getUserInfo<any>()
}

// 注册
export function register(data: User.RegisterData) {
  return userHttpRequest.register<null>(data)
}

// 发送邮箱验证码
export function sendCaptcha(data: User.CaptchaData) {
  return userHttpRequest.sendCaptcha<null>(data)
}

// 退出登录
export function logout() {
  return axios.post<User.LoginRes>("/user/logout")
}

// 获取菜单列表(菜单由服务端生成时启用)
export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>("/user/menu")
}

// 获取用户列表(分页)
export function getUserList(page: number = 1, pageSize: number = 10, searchQuery: any = null) {
  return userHttpRequest.getUserList<User.UserInfo[]>(page, pageSize, searchQuery)
}

// 新增用户
export function addUser(data: User.UserInfo) {
  return userHttpRequest.addUser(data)
}

// 修改用户
export function updateUser(id: string, data: User.UserInfo) {
  return userHttpRequest.updateUser(id, data)
}

// 删除用户
export function deleteUser(id: string) {
  return userHttpRequest.deleteUser(id)
}

// 重置密码
export function resetPassword(data: ResetPasswordData) {
  return userHttpRequest.resetPassword(data)
}

// 根据id获取用户信息
export function getUserInfoById(id: string) {
  return userHttpRequest.getUserInfoById<User.UserInfo>(id)
}
